<?php

namespace app\admin\model\goods;

use think\Model;
use traits\model\SoftDelete;

class Order extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'goods_order';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];



    public function getStatusList()
    {
        return ['1' => __('现金支付'),'2' => __('积分支付')];
    }
    public function getTypeList()
    {
        return ['0' => __('未支付'),'1' => __('已支付'),'3' => __('申请退款'),'4' => __('已退款'),'5' => __('已完成')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function User()
    {
        return $this->belongsTo(\app\admin\model\User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function Goods()
    {
        return $this->belongsTo(Info::class, 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
